package com.lee.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.lee.ssm.domain.Orders;
import com.lee.ssm.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/orders")
public class OroderController {

    @Autowired
    private IOrderService iOrderService;

    @RequestMapping("/findAll")
    public ModelAndView findAll(@RequestParam(name = "page" ,required = true ,defaultValue = "1") Integer page, @RequestParam(name = "size" ,required = true ,defaultValue = "4")Integer size){

        ModelAndView mv=new ModelAndView();
        List<Orders> orders=iOrderService.findAll(page,size);
        PageInfo pageInfo=new PageInfo(orders);
        mv.addObject("pageInfo",pageInfo);
        mv.setViewName("orders-list");
        return mv;
    }
    @RequestMapping("/findById")
    public ModelAndView findById(String id){
        ModelAndView mv=new ModelAndView();
        Orders orders = iOrderService.findById(id);
        mv.addObject("orders",orders);
        mv.setViewName("orders-show");
        System.out.println("=======================");
        System.out.println("||                    ||");
        System.out.println("数据库："+orders.getOrderTime());
        System.out.println("页面："+orders.getOrderTimeStr());
        System.out.println("数据库："+orders.getOrderStatus());
        System.out.println("页面："+orders.getOrderStatusStr());
        System.out.println("||                    ||");
        System.out.println("=======================");
        return mv;
    }
}
